<template>
  <section class="person-manage-main">
    <el-collapse-transition>
      <section v-show="searchshow" class="main-search merge">
        <span class="svg-container">
          <svg-icon icon-class="search" />
        </span>
        <el-input v-model.trim="listQuery.userName" placeholder="输入真实姓名搜索" class="search-input" @keyup.enter.native="handleFilter" />
        <section class="search-btn">
          <el-button class="filter-item" type="primary" @click="handleFilter">搜索</el-button>
          <el-button type="primary" @click="handleReset">重置</el-button>
          <!--          <span class="search-more" @click="searchshow = !searchshow">-->
          <!--            更多筛选条件-->
          <!--            <i class="el-icon-arrow-down" />-->
          <!--          </span>-->
        </section>
      </section>
    </el-collapse-transition>

    <section class="main-buttons">
      <section class="main-buttons-title">
        <span>报名信息</span>
      </section>
      <section class="main-buttons-btns">
        <el-button
          style="margin-left: 10px"
          @click="
            () => {
              $router.back()
            }
          "
        >返回</el-button>
        <el-button
          style="margin-left: 10px"
          @click="handleExport()"
        >导出</el-button>
      </section>
    </section>

    <section class="main-table">
      <!--      报名管理-->
      <v-table :list="list" tag="applicationRecord" :list-loading="listLoading" :filter-column="filtercolumn" :selection="false" />

      <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    </section>
  </section>
</template>
<script>
import Pagination from '@/components/Pagination'
import VTable from '@/components/Table'
import { RegqueryPage, maskAPI, noMaskAPI } from '../api'
import permission from '@/directive/permission/index.js'
import CryptoJS from '@/utils/aesJiaJM'
import { exportSign } from '@/utils/fileImportOrExportSign'
import { exportCheck } from '@/utils/sensitiveInfoExportCheck'
export default {
  name: 'PersonMangeIndex',
  components: { Pagination, VTable },
  directives: { permission },
  data() {
    return {
      classId: '', // 班级id
      id: '',
      listQuery: {
        page: 1,
        limit: 10,
        userName: ''
      },
      searchshow: true,
      search: {
        userName: '',
        userIdnumber: '',
        time: '',
        deptIds: []
      },
      list: [{}],
      total: 0,
      listLoading: false,
      view: '/API-DOCUMENT/document/file/download?id=',
      basisname: '',
      centerDialogVisible: false,
      dict: {
        AUDITRESULT: [] // 报名审核状态
      },
      remark: '',
      radio: '',
      selectRow: {},
      registInfoForm: {},
      registInfo: {}, // 报名表信息
      userInfo: {
        userName: '',
        phoneNum: '',
        idCard: '',
        location: ''
      },
      tag: 'trainingPersonMangeAuditno'
    }
  },
  async created() {
    if (!this.$route.query.id) {
      this.$message({
        showClose: true,
        message: '参数异常！',
        type: 'warning',
        onClose: () => {
          this.$router.back()
        }
      })
      return
    } else {
      this.classId = this.$route.query.id
      //   for (const key in this.dict) {
      //     await this.getDict(key)
      //   }
      await this.init()
    }
  },
  methods: {

    handleExport() {
      const query = exportSign({
        page: 1,
        pageSize: this.total,
        dataId: this.classId
      }).obj
      exportCheck('PK_REGISTRY', this.classId, maskAPI, noMaskAPI, query, '报名信息.xls')
    },
    async init() {
      await this.getList()
    },

    filtercolumn(scope, item) {
      if (item === 'authValue') {
        return `${this.basisname}：${scope.row[item]}`
      } else if (item === 'idCard' || item === 'phoneNum') {
        return CryptoJS.$aesJieM(scope.row[item])
      } else {
        return scope.row[item]
      }
    },

    handleReset() {
      this.listQuery.page = 1
      this.listQuery.userName = ''
      for (const i in this.search) {
        if (this.search['' + i + ''] instanceof Array) {
          this.search['' + i + ''] = []
        } else {
          this.search['' + i + ''] = ''
        }
      }
      this.getList()
    },

    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    /* handleView(row) {
        this.$router.push({ path: this.$filterPath('check'), query: { i: row.id, type: 'view' }})
      },*/

    getList(obj) {
      this.listLoading = true
      var query = {
        page: obj ? obj.page : this.listQuery.page,
        pageSize: obj ? obj.limit : this.listQuery.limit,
        dataId: this.classId
      }
      if (this.searchshow) {
        query['userName'] = this.listQuery.userName
      } else {
        query['userName'] = this.search.userName
        query['userIdnumber'] = this.search.userIdnumber
        query['deptIds'] = this.search.deptIds.length > 0 ? this.search.deptIds.join(',') : ''
        query['startcrtTime'] = this.search.time && this.search.time.length > 0 ? this.search.time[0] : ''
        query['endcrtTime'] = this.search.time && this.search.time.length > 0 ? this.search.time[1] : ''
      }
      return new Promise((resolve, reject) => {
        RegqueryPage(query)
          .then((response) => {
            this.list = response.data.data.rows
            this.total = response.data.data.total
            this.listLoading = false
          })
          .catch((error) => {
            reject(error)
            this.listLoading = false
          })
      })
    }
  }
}
</script>
  <style lang="scss">
  @import '@/styles/mixin.scss';

  .person-manage-main {
    padding: 10px;
    .main-search {
      background-color: #fff;
      padding: 0 10px;
      .svg-container {
        padding: 0 5px 0 10px;
        color: #bfced6;
        vertical-align: middle;
        display: inline-block;
      }
      .search-input {
        width: 60%;
        position: relative;
        &:after {
          content: '';
          position: absolute;
          left: -25px;
          right: 0;
          bottom: 8px;
          height: 1px;
          background: rgba(226, 227, 232, 1);
        }
        input {
          outline: none;
          background: transparent;
          border: none;
          outline: medium;
          padding: 0;
          &:focus {
            outline: none;
            background-color: transparent;
          }
        }
      }
      .search-btn {
        display: inline-block;
        float: right;
        .el-button.is-round {
          padding: 10px 30px;
          margin-right: 34px;
        }
        .search-more {
          font-size: 14px;
          font-weight: 500;
          @include font-color($mainColor);
          cursor: pointer;
          margin-left: 10px;
        }
      }

      &.merge {
        height: 50px;
        line-height: 50px;
      }

      &.separate {
        .search-inner {
          padding-top: 10px;
          .search-inner-item {
            .item-label {
              height: 30px;
              line-height: 30px;
              font-size: 14px;
              color: #a6a6a6;
              font-weight: 400;
            }
            .el-input {
              position: relative;
              &.el-date-editor input {
                padding-left: 30px;
              }
              .el-input__inner {
                border: none;
                padding: 0;
              }
              &:after {
                content: '';
                height: 1px;
                background-color: #e2e3e8;
                position: absolute;
                left: 0;
                right: 0;
                bottom: 0;
              }
            }
          }
        }
        .search-btn {
          text-align: center;
          display: block;
          float: none;
          height: 56px;
          line-height: 56px;
        }
      }
    }
    .classify-tab {
      width: 100%;
      margin-bottom: 10px;
      padding: 0 10px;
      background-color: #fff;
      display: flex;
      border-radius: 4px;
      .el-tabs__nav-wrap::after {
        display: none;
      }
      .el-tabs__header {
        margin: 0;
      }
    }
    .main-buttons {
      display: flex;
      line-height: 36px;
      margin-top: 10px;
      .main-buttons-title {
        flex: 1;
        height: 36px;
        line-height: 36px;
        font-size: 16px;
        font-weight: bold;
        color: rgba(51, 51, 51, 1);
      }
    }
    .user-con {
      span {
        margin-right: 15px;
        width: auto;
      }
      margin-bottom: 20px;
    }
    .information-list {
      display: flex;
      align-items: center;
      flex-wrap: wrap;
      span {
        //min-width: 60px;
        margin-right: 15px;
        width: auto;
      }
      .el-image {
        width: 80px;
        height: 80px;
        margin-right: 15px;
        img {
          width: 100%;
          height: 100%;
        }
      }
    }
  }
  </style>

